/*
"Replication Data for: The real-time impact of the war on Russian imports: 
a synthetic control method approach" by Mancini, Conteduca, Borin 

Fig6a.do: The files export figure 6a and the underlying data to a dta file

*/

clear  
cd "${main_loc}/"

  
 ************************************************************************************************************************
 use  "${main_loc}/data_TurkeyHT_WTR",clear


drop if partner=="Ukraine"	
drop if partner=="Turkey"	
drop if partner=="Kazakhstan"	
drop if partner=="Belarus"	
drop if partner=="Serbia"	
drop if partner=="Armenia"
drop if partner=="Uzbekistan"
drop if partner=="Kyrgyzstan"
drop if partner=="Georgia"
drop if partner=="Azerbaijan"

 
  
 
egen id=group(iso2_d),label
egen t=group(date)
tsset id t

drop if BVlndist==.
drop if BVcontiguity==.
drop if BVcommon_language==.
drop if lnagdp_wdi_const==.
 drop if lnavg_outp==.

tsfill,full
replace value=0 if value==.

sort id t
local varl  BVlndist BVcontiguity BVcommon_language lnagdp_wdi_const  max_agree_pta_goods max_agree_cu  lnavg_outp
foreach x of local varl {  
sort id `x' 
by id: carryforward `x' ,replace
}

 
sort id t
gen date_new=date  
order id date date_new 

bys id: replace date_new=l.date_new+1 if date_new==.
bys id: replace date_new=l2.date_new+2 if date_new==.
bys id: replace date_new=l3.date_new+3 if date_new==.
bys id: replace date_new=l4.date_new+4 if date_new==.
bys id: replace date_new=l5.date_new+5 if date_new==.
bys id: replace date_new=f.date_new-1 if date_new==.
bys id: replace date_new=f2.date_new-2 if date_new==.
bys id: replace date_new=f3.date_new-3 if date_new==.
bys id: replace date_new=f4.date_new-4 if date_new==.
bys id: replace date_new=f5.date_new-5 if date_new==.
format date_new %tm
drop date fdate year  month
rename date_new date

gen fdate = dofm(date)
gen year=year(fdate)
gen month=month(fdate)
gen dm=month
 


 
 keep if t>=13

sort id t

summ id if partner=="Russia"
capture   synth   value   value BVlndist BVcontiguity BVcommon_language  lnavg_outp  s1 s2  s3  s4  max_agree_pta_goods ,   trunit("`r(mean)'") trperiod(38)    figure     keep("${main_loc}/Figure_6a",replace)  
 
   graph export "${main_loc}/Figure_6a.png",replace
 
 

 
 
